﻿namespace Sai.Cecil
{
	using Sai.Core.Introspection;
	using Mono.Cecil;

	/// <summary>
	/// Factory type extension to build a declarations from equivalent mono definition objects.
	/// </summary>
	public static class PropertyDefinitionExtensions
	{
		/// <summary>
		/// Creates a property declaration from the equivalent mono property definition.
		/// </summary>
		/// <param name="property">The property.</param>
		/// <returns>The property object.</returns>
		public static PropertyDeclaration ToPropertyDeclaration(this PropertyDefinition property)
		{
			// can we tell if it's public ???
			var propertyType = new PropertyDeclaration(
												property.Name,
												property.PropertyType.ToTypeName(),
												property.BuildObsoleteMarker(),
												property.DeclaringType.ToTypeName())
			{
				HasPublicGetter = property.HasPublicGetter(),
				HasPublicSetter = property.HasPublicSetter()
			};

			return propertyType;
		}
	}
}
